import 'package:flutter/material.dart';

class RouteDemo extends StatefulWidget {
	@override
	State<StatefulWidget> createState() {
		return RouteDemoState();
	}
}

class Todo extends Object {
	String title;
	String desc;

	Todo(this.title, this.desc);
}

class RouteDemoState extends State<RouteDemo> {

	var todos = <Todo>[];

	@override
	void initState() {
		super.initState();

		todos = List.generate(20, (index) {
			return Todo("title of ${index}", "this is todo desc of ${index}");
		});

	}

	@override
	Widget build(BuildContext context) {
		return new Scaffold(
			appBar: AppBar(
				title: Text("Route Demo"),
			),
			body: ListView.builder(
				itemBuilder: (BuildContext context, int index) {
					return _buildItem(context, index);
				},
				itemCount: todos.length,
			),
		);
	}

	Widget _buildItem(BuildContext context, int index) {
		Todo todo = todos[index];
		String title = todo.title;
		return ListTile(
			title: Text(title),
			onTap: () {
				Navigator.push(
					context,
					new MaterialPageRoute(
						builder: (BuildContext context) {
							return new TodoDetailPage(todo: todo,);
						}
					)
				);
			},
		);
	}
}

class TodoDetailPage extends StatelessWidget {

	Todo todo;

	TodoDetailPage({this.todo});

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text("Todo Detail"),
			),
			body: Center(
				child: Text("Detail: ${todo.desc}"),
			),
		);
	}
}